﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LinkedInApi
{
    public class ApiError
    {
        public Exception InnerException { get; private set; }
        public string Error { get; private set; }
        public string Description { get; private set; }

        public bool IsApiError
        {
            get
            {
                return this.InnerException == null;
            }
        }

        internal ApiError(string error, string description)
        {
            this.Error = error;
            this.Description = description;
            this.InnerException = null;
        }

        internal ApiError(Exception e)
        {
            this.InnerException = e;
            this.Error = this.InnerException.GetType().ToString();
            this.Description = this.InnerException.Message;
        }

        public override string ToString()
        {
            if (this.IsApiError)
                return String.Format("Error - {0}, description - {1}", this.Error, this.Description);
            else
                return this.InnerException.ToString(); 
        }
    }
}
